/*
 * 	Name		: LMX2541.h
 *	Author	 	: Tigran Papazyan
 *  Created on	: Nov 18, 2010
 *  Copyright   : Copyright Antel Systems
 *  Description : LMX2541 PLL Driver
 */

#ifndef LMX2541_H_
#define LMX2541_H_

#include "compiler.h"

#define RATED_FREQUENCY 415006250


#define LMX2541_DATA_LENGTH_BITS_8		8
#define LMX2541_DATA_LENGTH_BITS_16	16
#define LMX2541_DATA_LENGTH_BITS_32	32

struct LMX2541_Registers
{
	unsigned int   REG7;
	union
	{
		struct
		{
			unsigned int	RESERVED_	: 25;
			unsigned int	VCO_DIV_OPT	: 3;
			unsigned int	address 	: 4;
		} REG13_bits;
		unsigned int   DWORD_REG13;
	} REG13;

	unsigned int   REG12;

	unsigned int   REG9;

	union
	{
		struct
		{
			unsigned int	RESERVED_	: 24;
			unsigned int	AC_TEMP_COMP: 4;
			unsigned int	address 	: 4;
		} REG8_bits;
		unsigned int   DWORD_REG8;
	} REG8;

	union
	{
		struct
		{
			unsigned int	RESERVED_	: 14;
			unsigned int	VCO_GAIN	: 4;
			unsigned int	OUT_TERM	: 4;
			unsigned int	DIV_GAIN	: 4;
			unsigned int	RF_OUT		: 2;
			unsigned int	address 	: 4;
		} REG6_bits;
		unsigned int   DWORD_REG6;
	} REG6;

	union
	{
		struct
		{
			unsigned int	RESERVED_	: 3;
			unsigned int	FL_CPG		: 5;
			unsigned int	FL_R4_LF	: 3;
			unsigned int	FL_R3_LF	: 3;
			unsigned int	FL_TOC		: 14;
			unsigned int	address 	: 4;
		} REG5_bits;
		unsigned int   DWORD_REG5;
	} REG5;

	union
	{
		struct
		{
			unsigned int	C4_LF		: 4;
			unsigned int	C3_LF		: 4;
			unsigned int	R4_LF		: 3;
			unsigned int	R3_LF		: 3;
			unsigned int	VCO_DIV		: 6;
			unsigned int	OSC_FREQ	: 8;
			unsigned int	address 	: 4;
		} REG4_bits;
		unsigned int   DWORD_REG4;
	} REG4;

	union
	{
		struct
		{
			unsigned int	FSK			: 1;
			unsigned int	reserved	: 2;
			unsigned int	DLOCK		: 3;
			unsigned int	CPT			: 1;
			unsigned int	DITH		: 2;
			unsigned int	ORDER		: 3;
			unsigned int	FDM			: 1;
			unsigned int	OSC_2X		: 1;
			unsigned int	CPP			: 1;
			unsigned int	MUX			: 4;
			unsigned int	CPG			: 5;
			unsigned int	XO			: 1;
			unsigned int	POWER_DOWN	: 1;
			unsigned int	MODE		: 2;
			unsigned int	address 	: 4;
		} REG3_bits;
		unsigned int   DWORD_REG3;
	} REG3;

	union
	{
		struct
		{
			unsigned int	RESERVED_	: 6;
			unsigned int	DEN			: 22;
			unsigned int	address 	: 4;
		} REG2_bits;
		unsigned int   DWORD_REG2;
	} REG2;

	union
	{
		struct
		{
			unsigned int	RESERVED_	: 4;
			unsigned int	PLL_NUM		: 6;
			unsigned int	PLL_N		: 6;
			unsigned int	PLL_R		: 12;
			unsigned int	address 	: 4;
		} REG1_bits;
		unsigned int   DWORD_REG1;
	} REG1;

	union
	{
		struct
		{
			unsigned int	PLL_NUM		: 16;
			unsigned int	PLL_N		: 12;
			unsigned int	address 	: 4;
		} REG0_bits;
		unsigned int   DWORD_REG0;
	} REG0;

} LMX_REG ;

U64 LMX2541_Frequency ;
S64 LMX_Freq_Error ;

//Prototypes
int LMX2541_Init(void);
void LMX2541_Write(unsigned char* ,unsigned int byte_count, unsigned int word_length_bit);
void LMX2541_Read(unsigned int data , unsigned int bit_count);
void LMX2541_Get_Status();

int LMX2541_Set_Frequency(U64 F_Out_in_hz);

void LMX2541_Sleep_Wake(unsigned char state );
unsigned int LMX2541_Lock_Detect(void);
int LMX2541_Set_Chanel_Freq(void);
int Find_Frequency_Band(unsigned int freq_hz , unsigned int* multiplier);
int LMX2541_Freq_Error(void);

#endif /* LMX2541_H_ */

